#include "log.h"

static char gLogStrBuf[LOG_BUF_LEN + 4];
char*       gLogStrH = 0;
char*       gLogStr = 0;

void Log_init(void)
{
    gLogStrH = gLogStrBuf;
    gLogStr = gLogStrBuf + 2;
}

#define LOG_BUF_LEN     128

extern usb_core_driver cdc_acm;
extern char* gLogStrH;
extern char* gLogStr;

#define LOG_PRINT(x) \
{ \
    int len = 0; \
    gLogStrH[0] = 'I'; \
    gLogStrH[1] = ':'; \
    len = sprintf x; \
    gLogStr[len] = 0; \
    printf(gLogStrH); \
    cdc_acm_data_send_data(&cdc_acm, (uint8_t *)gLogStr, strlen(gLogStr)); \
}

#define ERR_PRINT(x) \
{ \
    int len = 0; \
    gLogStrH[0] = 'E'; \
    gLogStrH[1] = ':'; \
    len = sprintf x; \
    gLogStr[len] = 0; \
    printf(gLogStrH); \
    cdc_acm_data_send_data(&cdc_acm, (uint8_t *)gLogStr, strlen(gLogStr)); \
}

void Log_init(void);